package office;

import com.spire.xls.ExcelVersion;
import com.spire.xls.Workbook;
import com.spire.xls.Worksheet;
import org.junit.jupiter.api.Test;

import static office.T1.excel;

public class T2 {

    @Test
    public void t0() {
        //加载测试文档
        Workbook wb = new Workbook();
        wb.loadFromFile(excel);

        //获取第一个工作表
        Worksheet sheet1 = wb.getWorksheets().get(0);

        //获取第二个工作表
        Worksheet sheet2 = wb.getWorksheets().get(1);

        //复制工作表1中的单元格区域到工作表2
        sheet2.copy(sheet2.getCellRange("B3:L12"), sheet1.getCellRange("A44:L56"), true);
        //在工作表2中设置列宽自适应文字长度
        for (int i = 0; i < 8; i++) {

            sheet2.autoFitColumn(i + 1);
        }

        //保存文档
        wb.saveToFile(excel, ExcelVersion.Version2016);
    }

}
